package com.huike.clues.service.impl;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author: qingtao
 * @Date 2022/3/31 17:27
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;

    /**
     * 根据线索id查询线索跟进记录
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecord(Long clueId) {

        return tbClueTrackRecordMapper.selectTbClueTrackRecord(clueId);
    }

    /**
     * 添加线索跟进
     */
    @Override
    @Transactional
    public boolean saveCluesTrackRecord(TbClueTrackRecord tbClueTrackRecord, TbClue tbClue){
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord.setCreateTime(new Date());
        tbClueTrackRecord.setType("0");
        tbClueTrackRecordMapper.saveCluesTrackRecord(tbClueTrackRecord);
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbClue.setId(tbClueTrackRecord.getClueId());
        tbClueMapper.updateTbClue(tbClue);
        return true;
    }
}
